# 这是使用AI生成的脚本,"咒语"如下:

# 使用python编写一个程序,disk.img是一个128MB的二进制文件,我需要打开它,以每512B为一块处理这个文件.
# 1)如果这一块的512字节全部为0,不进行任何处理.
# 2)如果这一块的512字节存在非零值,参考如下格式打印:
# const uint8_t msc_block_xxx[512] =
# {
# 	0xEB, 0x3C, 0x90, 0x4D, 0x53, 0x44, 0x4F, 0x53, 0x35, 0x2E, 0x30, 0x00, 0x02, 0x01, 0x01, 0x00,
# 	......
# 	......
# 	......
# };
# 其中的xxx应当替换为块的序号使用python编写一个程序,disk.img是一个128MB的二进制文件,我需要打开它,以每512B为一块处理这个文件.


def process_disk_image(file_path):
    with open(file_path, 'rb') as f:
        block_size = 512
        block_count = 128 * 1024 * 1024 // block_size  # Calculate the number of blocks in 128MB

        for block_index in range(block_count):
            block_data = f.read(block_size)

            if all(byte == 0 for byte in block_data):  # Check if all bytes are zero
                continue  # Skip processing and move to the next block

            print(f"const uint8_t msc_block_{block_index:03}[512] = {{")
            for i in range(0, len(block_data), 16):  # Print 16 bytes per line
                line_data = block_data[i:i + 16]
                hex_values = ', '.join(f'0x{byte:02X}' for byte in line_data)
                print(f"    {hex_values},")
            print("};")

if __name__ == "__main__":
    process_disk_image('disk.img')